home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 183_01 / sdira.asm < prev    next >
Assembly Source File  |  1985-12-14  |  12KB  |  279 lines

  1. page ,132
  2. title **** DIRGT.ASM ***
  3. comment *
  4.  
  5. =========================================================================
  6. DIRGT.ASM
  7. 03-06-85  by  Thomas E. Link
  8.  
  9.         If using LATTICE C delete that line.
  10. =========================================================================
  11. *
  12. page
  13. workstruc       struc
  14.         dircount        dw      (?)
  15.         dos_version     db      (?)
  16.         filler          db      (?)
  17.         saved_sp        dw      (?)
  18.         fcb             db      48 dup (?)
  19.         dta             db      48 dup (?)
  20. workstruc       ends
  21.  
  22. stack   struc                      ; Define the stack area for C.
  23.         workarea        db      type workstruc dup (?)
  24.         pushed_bp       dw      (?)
  25.         address         dw      (?)
  26.         countnumad      dw      (?)
  27.         volstrgad       dw      (?)
  28.         dirrecarad      dw      (?)
  29.         lookstringad    dw      (?)
  30. stack   ends
  31.         poplen  equ     0
  32.  
  33.  
  34. _DATA   segment word public  'DATA'
  35. _DATA   ends
  36. dgroup  group   _data
  37.         assume ds:dgroup
  38.  
  39. pgroup  group   _text
  40.         assume  CS:pgroup
  41. _TEXT   segment byte public  'CODE'
  42.         public  _DIRGET
  43. _DIRGET proc    near
  44.  
  45. DIRGET_:
  46.         cld                          ; Clear direction flag.
  47.         push    bp
  48.         mov     bp,sp                ; Point to arguments on stack.
  49.         push    di
  50.         push    si
  51.         sub     bp,type workstruc    ; Give us room to work
  52.         mov     [bp].saved_sp,sp     ; Save the stack pointer
  53.         mov     sp,bp                ; and move it below workarea.
  54.         mov     [bp].dircount,0      ; Move zero to directory count.
  55.  
  56. ;----------------- determine DOS version, store in variable
  57.         mov     ah,48                ; find DOS version number
  58.         int     21h
  59.         mov     [bp].dos_version,al  ; and store in variable
  60.  
  61. ;-----------------  parse filename
  62.         mov     ax,ss
  63.         mov     es,ax           ; Have ES point at STACK **************
  64.         mov     di,bp           ; and DI point
  65.         add     di,offset fcb   ;            to FCB area.
  66.         mov     si,[bp].lookstringad    ; Point SI at file specifier
  67.         mov     ah,29H          ; DOS function to parse filename
  68.         mov     al,1            ; scan off leading separators
  69.         int     21H             ; DOS function call
  70.         push    ds              ; Get DATA seg into ES.***************
  71.         pop     es
  72.         cmp     al,0FFH         ; Any errors on parsing ?
  73.         jne     dir2            ; No - continue
  74.         jmp     done            ; YES - end.
  75.  
  76. ;----------------- get addresses of the parms
  77. dir2:
  78.         mov     dx,bp           ; Put address of workspace into DX
  79.         add     dx,offset dta   ; Bump to DTA
  80.         push    ds              ; Save value of DS
  81.         mov     ax,ss           ; and move STACK into DS.**************
  82.         mov     ds,ax
  83.         mov     ah,1AH          ; Set AH for *SET DTA* function call.
  84.         int     21H             ; Use DOS interrupt.
  85.  
  86.         cmp     [bp].dos_version,2 ; if DOS 2.0 or greater
  87.         jae     dos2_search        ; use special routine
  88.  
  89. ;----------------- DOS 1.0, 1.1 search
  90.         mov     dx,bp           ; Point DX at workspace
  91.         add     dx,offset fcb   ;       bump to FCB area.
  92.         mov     ah,11H          ; Set AH for directory search.
  93.         int     21H             ; Use DOS interrupt.
  94.         cmp     al,0FFH         ; Any matches found ?
  95.         je      done1           ; No - so end
  96.         inc     [bp].dircount   ; Yes - count first entry.
  97.         call    move            ; Go move entry into fnames().
  98. dirloop:
  99.         mov     ah,12H          ; Set AH for continuation of search.
  100.         int     21H             ; Use DOS interrupt.
  101.         cmp     al,0FFH         ; Any matches found ?
  102.         je      done1           ; No - jump to exit
  103.         inc     [bp].dircount   ; Yes - count this entry.
  104.         call    move            ; Go move entry into arrays.
  105.         jmp     dirloop         ; Do again.
  106.  
  107. ;----------------- DOS 2.x  search
  108. dos2_search:
  109.         mov     dx,[bp].lookstringad    ; Point DX at file specifier
  110.         mov     ah,4EH          ; Set AH for directory search.
  111.         mov     cx,10H          ; search for files and directories.
  112.         int     21H             ; Use DOS interrupt.
  113.         jc      findlabel       ; No matches - so look for a label
  114.         inc     [bp].dircount   ; found - count first entry.
  115.         call    move2           ; Go move entry into arrays.
  116. dir2loop:
  117.         mov     cx,10H
  118.         mov     ah,4FH          ; Set AH for continuation of search.
  119.         int     21H             ; Use DOS interrupt.
  120.         jc      findlabel       ; No matches - so look for a label
  121.         inc     [bp].dircount   ; match - count this entry.
  122.         call    move2           ; Go move entry into arrays.
  123.         jmp     dir2loop        ; Do again.
  124. findlabel:
  125.         call    get_label       ; look for a volume label
  126. done1:
  127.         pop     ds              ; restore DS to DATA  ****************
  128. done:
  129.         mov     ax,[bp].dircount      ; Move entries count to AX.
  130.         mov     di,[bp].countnumad    ; Get address of COUNT%
  131.         mov     [di],ax         ; Put entry count in COUNT%.
  132.         mov     sp,[bp].saved_sp      ; Restore SP.
  133.         pop     si
  134.         pop     di
  135.         pop     bp              ; Restore BP.
  136.         ret     poplen          ; Return and throw away parms if PASCAL
  137.  
  138. ;........................................................................
  139. ;----------------- procedure to store results from DOS 1.x search
  140. move    proc    near
  141. ;----------------- first move filename into string array
  142.         mov     di,[bp].dirrecarad   ; Move name address to DI and BX.
  143.         mov     bx,di
  144.         add     bx,20           ; Have BX point at next record
  145.         mov     [bp].dirrecarad,bx   ; and save in variable
  146.         mov     si,bp
  147.         add     si,offset dta+1 ; put file name(in DTA) address into SI
  148.         mov     cx,4            ; Length of name in words
  149.         rep     movsw           ; Move name into array.
  150.         mov     byte ptr [di],'.' ; Put period in filename.
  151.         inc     di              ; Bump DI past '.'
  152.         mov     cx,3            ; Length of extension in bytes
  153.         rep     movsb           ; Move extension into array.
  154. ;-----------------  get the file time into array
  155.         add     si,11           ; move to file time area
  156.                 movsw           ; Move time into array.
  157. ;-----------------  get the file date into array
  158.                 movsw           ; Move size into array.
  159. ;-----------------  get the file length into array
  160.         add     si,2            ; Point SI at file size.
  161.                 movsw           ; Move size into array.
  162.                 movsw
  163.         ret
  164. move    endp
  165.  
  166. ;........................................................................
  167. ;----------------- procedure to store results of DOS 2.x search
  168. move2   proc    near
  169. ;----------------- first get the file time into array
  170.         mov     si,bp
  171.         add     si,offset dta +22 ; Point AX at DTA + 22
  172.         mov     bx,[bp].dirrecarad    ; Move record address to BX and DI.
  173.         mov     di,bx
  174.         add     di,12           ; Bump DI to time.
  175.                 movsw           ; Move time into array.
  176. ;----------------- now get the file date into array
  177.                 movsw           ; Move size into array.
  178. ;----------------- get the file length into array
  179.                 movsw           ; Move size into array.
  180.                 movsw
  181. ;-----------------  move filename into string array
  182.         mov     di,bx           ; Point DI at name.
  183.         add     bx,20           ; Bump BX to next record.
  184.         mov     [bp].dirrecarad,bx ; Save it in variable space.
  185.         mov     cx,8            ; Length of name in bytes
  186. move201:
  187.                 lodsb           ; Move character into al
  188.         cmp     al,'.'          ; If is it a period ... jump.
  189.         je      move202
  190.         cmp     al,0            ; If zero - dont jump.
  191.